#!bin/bash
function connMysqlAndMoreResColunm
{

	sql_stat=$1
	MYSQL_IP=10.160.255.7
	USERNAME=yuxin_mysql
	MYSQL_PORT=3306
	PASSWORD=srcb@yuxin
	res=$(mysql -h${MYSQL_IP} -P${MYSQL_PORT} -u${USERNAME} -p${PASSWORD} -D hive -e"${sql_stat}" 2>>./mysql.log )
	echo "$res"
}

function connMysqlAndMoreResColunmNoH
{

	sql_stat=$1
	MYSQL_IP=10.160.255.7
	USERNAME=yuxin_mysql
	MYSQL_PORT=3306
	PASSWORD=srcb@yuxin
	res=$(mysql -h${MYSQL_IP} -P${MYSQL_PORT} -u${USERNAME} -p${PASSWORD} -D hive -Ne"${sql_stat}" 2>>./mysql.log )
	echo "$res"
}
function connMysqlAndOneResColunm
{

	sql_stat=$1
	MYSQL_IP=10.160.255.7
	USERNAME=yuxin_mysql
	MYSQL_PORT=3306
	PASSWORD=srcb@yuxin
	res=$(mysql -h${MYSQL_IP} -P${MYSQL_PORT} -u${USERNAME} -p${PASSWORD} -D hive -e"${sql_stat}" 2>>./mysql.log )
	res=`echo $res | awk '{print $2}'`
	echo "$res"
}


#psql -h16.164.2.9  -p 5432 -U tbase -d postgres -WSrcb@12345
#mysql -h10.160.255.7 -uyuxin_mysql -psrcb@yuxin

#select count(1) from o_tbase_idxm.o_deps_acct_rmns_info;
function connTBaseAndOneResColunm
{

	sql_stat=$1
	MYSQL_IP=16.164.2.9
	USERNAME=tbase
	MYSQL_PORT=5432
	res=$(psql -h${MYSQL_IP} -p${MYSQL_PORT} -U${USERNAME} -d postgres -c "${sql_stat}" 2>>./tabse.log )
	#res=`echo $res | awk '{print $2}'`
	echo "$res"
}
function printMsgInRed()
{
    echo -e "\033[31m $* \033[0m"
}
function hive_export_file
{
        export_tb=$1
        export_sql=$2
        #res=$(beeline -u jdbc:hive2://10.160.255.43:10000,10.160.255.47:10000 -n hive -p hive@Tbds.com --outputformat=csv  --delimiter=, --showHeader=false --convertBinaryArrayToString=true -e"${export_sql}" 2>${export_tb}_run.log )       
        res=$(beeline -u jdbc:hive2://10.160.255.43:10000,10.160.255.47:10000 -n hive -p hive@Tbds.com --outputformat=csv2  --showHeader=false --hiveconf hive.exec.compress.output=false -e"${export_sql}" 2>${export_tb}_run.log )       
        #res=$(beeline -u jdbc:hive2://10.160.255.43:10000,10.160.255.47:10000 -n hive -p hive@Tbds.com  --outputformat=csv2 -e"${export_sql}" >> ${export_tb}.log 2>&1) 
        echo "$res"
}
